package hadoop.mapreduce.wordcountcombiner;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    /**
     *
     * @param key 偏移量,一行数据的开始位置
     * @param value 一行数据
     * @param context 输出对象
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String string = value.toString();
        String[] words = string.split(" ");
        for (String word : words) {
            context.write(new Text(word),new IntWritable(1));
        }
        //输出结果模板为{a,1} {a,1} {b,1} {c,1} {c,1}

    }
}
